﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.LogManage;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.LogManage.Operation
{
    public class OperationLogServeice : IOperationLogServeice
    {
        private readonly IRepository<OperationLog> _studentService;

        public OperationLogServeice(IRepository<OperationLog> studentService)
        {
            _studentService = studentService;
        }

        public async Task<Response<List<OperationLog>>> GetOperationLog(Omodel omodel)
        {
            var obj = await _studentService.GetAllListAsync();


            if (!string.IsNullOrWhiteSpace(omodel.systemModule))
            {
                obj = obj.Where(x => x.SystemModule.Contains(omodel.systemModule)).ToList();
            }

            if (!string.IsNullOrEmpty(omodel.isDelete))
            {
                if (omodel.isDelete == "true")
                {
                    obj = obj.Where(x => x.IsDelete == true).ToList();
                }
                else
                {
                    obj = obj.Where(x => x.IsDelete == false).ToList();
                }
            }

            if (omodel.station.HasValue && omodel.enddate.HasValue)
            {
                obj = obj.Where(x => x.OperationDate > omodel.station && x.OperationDate < omodel.enddate).ToList();
            }

            //总条数
            int total = obj.Count();
            //分页
            obj = obj.Skip((omodel.pageIndex - 1) * omodel.pageSize).Take(omodel.pageSize).ToList();

            var result = obj.MapToList<OperationLog>();
            return Response<List<OperationLog>>.Ok(result, total);
        }
    }

    public class Omodel
    {
        public int pageIndex { get; set; }

        public int pageSize { get; set; }
        public string? systemModule { get; set; }

        public string? isDelete { get; set; }

        public DateTime? station { get; set; }

        public DateTime? enddate { get; set; }
    }
}
